package com.ww.microrpc.netty;

import com.ww.microrpc.netty.protocol.ErrorMessage;
import com.ww.microrpc.netty.protocol.Message;
import com.ww.microrpc.netty.protocol.RequestMessage;
import com.ww.microrpc.netty.protocol.ResponseMessage;

import java.util.HashMap;
import java.util.Map;

/**
 * @author iiwan
 */
public interface Constant {

    interface MessageType {
        int RpcRequest = 1;
        int RpcResponse = 2;
        int RequestMessage = 3;
        int ErrorMessage = 4;
    }

    int SERIALIZER_DEFAULT = 0;
    int SERIALIZER_JSON = 1;
    int SERIALIZER_JDK = 2;
    int SERIALIZER_HESSIAN = 3;
    int SERIALIZER_KRYO = 4;
    int SERIALIZER_PROTOSTUFF = 5;

    Map<Integer, Class<? extends Message>> messageClasses = new HashMap<>() {{
        put(MessageType.RpcRequest, RequestHolder.class);
        put(MessageType.RpcResponse, ResponseMessage.class);
        put(MessageType.RequestMessage, RequestMessage.class);
        put(MessageType.ErrorMessage, ErrorMessage.class);
    }};

//    private static final Map<Integer, Class<? extends Message>> messageClasses = new HashMap<>() {{
//        put(MessageType.RpcRequest, RpcRequest.class);
//        put(MessageType.RpcResponse, RpcResponse.class);
//    }};

    public static Class<? extends Message> getMessageClass(int messageType) {
        return messageClasses.get(messageType);
    }

}
